const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const MiniProgram = sequelize.define('MiniProgram', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '小程序名称'
  },
  app_id: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '小程序ID'
  },
  app_secret: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '小程序密钥'
  },
  config: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '小程序配置'
  },
  qr_codes: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '小程序二维码'
  },
  status: {
    type: DataTypes.ENUM('active', 'inactive', 'maintenance'),
    defaultValue: 'active',
    comment: '小程序状态'
  },
  version: {
    type: DataTypes.STRING,
    comment: '小程序版本'
  },
  description: {
    type: DataTypes.TEXT,
    comment: '小程序描述'
  },
  domain: {
    type: DataTypes.STRING,
    comment: '小程序域名'
  },
  server_domain: {
    type: DataTypes.STRING,
    comment: '小程序服务器域名'
  },
  payment_config: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '小程序支付配置'
  },
  template_ids: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '小程序模板ID'
  },
  statistics: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '小程序统计数据'
  },
  metadata: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '元数据'
  }
}, {
  underscored: true,
  indexes: [
    {
      unique: true,
      fields: ['app_id']
    }
  ],
  comment: '小程序信息表'
});

module.exports = MiniProgram; 